﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BidFunLib.Entity
{
    /// <summary>
    /// This class is managing a bid performed in a sale by one user.
    /// </summary>
    public class BidLogger
    {
        /// <summary>
        /// technical unique key used in persitance tier. 
        /// </summary>
        virtual public Int32 IdBidLogger { get; set; }

        /// <summary>
        /// Time left before(TODO ? a verifier) this bid
        /// </summary>
        virtual public String Span_time { get; set; }

        /// <summary>
        /// Amount of the bid
        /// </summary>
        virtual public String Amount { get; set; }


        virtual public Double AmountAsDouble
        {
            get
            {
                Double res = 0;
                if (Amount !=  null) {
                    Double.TryParse(Amount.Replace(".", ",").Replace("€", ""), out res);
                }
                return res; 
            }
            set
            {
                AmountAsDouble = value;
            }
        }


        /// <summary>
        /// Object de la vente
        /// </summary>
        private BidOperatorType bidOperatorType;         
        /// <summary>
        /// Type of operator that perform the bid (human/bidfunbot)
        /// </summary>
        virtual public BidOperatorType BidOperatorType
        {
            get
            {
                return bidOperatorType;
            }
            set
            {
                bidOperatorType = value;
                IdBidOperatorType = bidOperatorType.IdBidOperatorType;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        virtual public Int32 IdBidOperatorType { get; set; }
      
        /// <summary>
        /// Utilisateur qui a encherie peut etre null si l'enchere est réalisé par notre robot
        /// </summary>
        virtual public BidUser BidUser
        {
            get
            {
                return bidUser;
            }
            set
            {
                bidUser = value;
                IdBidUser = bidUser.IdBidUser;
            }
        }
        private BidUser bidUser;


        /// <summary>
        /// Utilisateur qui a encherie peut etre null si l'enchere est réalisé par notre robot
        /// </summary>
        virtual public Int32 IdBidUser{ get; set; }
       
        /// <summary>
        /// Lien vers la vente
        /// </summary>
        virtual public BidSale BidSale
        {
            get
            {
                return bidSale;
            }
            set
            {
                bidSale = value;
                IdBidSale = bidSale.IdBidSale;
            }
        }

        private BidSale bidSale;

        /// <summary>
        /// 
        /// </summary>
        virtual public Int32 IdBidSale { get; set; }
      

        /// <summary>
        /// Oui cette enchere a gagné la vente, non sinon
        /// </summary>
        virtual public Boolean Winner { get; set; }

        /// <summary>
        /// nb d'utilisateurs connectés au moment de l'enchère
        /// </summary>
        virtual public Int32 NbUserConnected { get; set; }

        /// <summary>
        /// Date and time of the bid 
        /// </summary>
        virtual public DateTime DateTime { get; set; }

        // private BidBot = null;

        // default constructor mandatory for nhibernate
        public BidLogger()
        {
            IdBidLogger = -1;
            BidOperatorType = new BidOperatorType("NONE");
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="span_time">Temps restant</param>
        /// <param name="amount"></param>
        /// <param name="type">manuel / auto</param>
        /// <param name="dateTime"></param>
        public BidLogger(String span_time, String amount, BidOperatorType type, String dateTime)
        {
            IdBidLogger = -1;
            Span_time = span_time;
            Amount = amount;
            BidOperatorType = type;
            DateTime = DateTime.Parse(dateTime);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="amount"></param>
        public BidLogger(String amount)
        {
            IdBidLogger = -1;
            Amount = amount;
        }
    }
}
